﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sisocana.Core.Interfaces;
using Sisocana.Dal;
using Sisocana.Dal.Interfaces;
using Sisocana.Dal.EntityModels;
using Sisocana.Core.Models;
using System.IO;


namespace Sisocana.Core
{
    public class MasterPageCatService:ServiceBase<IMasterPageCatModel>,IMasterPageCatService
    {


        public MasterPageCatService()
            : this(new MasterPageCatRepository())
        {
        }

        private IMasterPageCatRepository _MasterPageCatRepository;

        public MasterPageCatService(IMasterPageCatRepository RedesSocialesRepository)
        {
            _MasterPageCatRepository = RedesSocialesRepository ?? new MasterPageCatRepository();
        }

        public void createMasterPageCatMapperEF2Model()
        {
            AutoMapper.Mapper.CreateMap<MasterPageCat, MasterPageCatModel>();            
        }

        public void createMasterPageCatMapperModel2EF()
        {
            AutoMapper.Mapper.CreateMap<MasterPageCatModel, MasterPageCat>();            
        }

        public void addMasterPage(MasterPageCatModel masterModel)
        {
            createMasterPageCatMapperModel2EF();
            if(_MasterPageCatRepository.Count(mp => mp.nombreMaster.Trim().Equals(masterModel.nombreMaster,StringComparison.CurrentCultureIgnoreCase)) > 0)
                throw new Exception(String.Format("A master page with name '{0}' already exists", masterModel.nombreMaster));

            MasterPageCat masterPage = new MasterPageCat();
                
            masterPage = AutoMapper.Mapper.Map(masterModel, masterPage);
            _MasterPageCatRepository.Add(masterPage);
            _MasterPageCatRepository.Save();
        }

        public int createMasterPageCat(Models.MasterPageCatModel masterPageCat)
        {
            throw new NotImplementedException();
        }

        public IList<MasterPageCatModel> GetAll()
        {
            createMasterPageCatMapperEF2Model();

            IList<MasterPageCat> mpsEF = _MasterPageCatRepository.GetAll();
            List<MasterPageCatModel> mps = new List<MasterPageCatModel>();
            foreach (MasterPageCat mpEF in mpsEF)
            {
                MasterPageCatModel mp = new MasterPageCatModel();
                mp = AutoMapper.Mapper.Map(mpEF, mp);
                mps.Add(mp);
            }
            return mps;
        }       

        public MasterPageCatModel GetSingle(System.Linq.Expressions.Expression<Func<MasterPageCatModel, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public void Add(MasterPageCatModel entity)
        {
            throw new NotImplementedException();
        }

        public void Delete(MasterPageCatModel entity)
        {
            throw new NotImplementedException();
        }

        public void Update(MasterPageCatModel entity)
        {
            throw new NotImplementedException();
        }

        public IList<MasterPageCatModel> GetAll(System.Linq.Expressions.Expression<Func<MasterPageCatModel, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public IQueryable<MasterPageCatModel> Query(System.Linq.Expressions.Expression<Func<MasterPageCatModel, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public long Count(System.Linq.Expressions.Expression<Func<MasterPageCatModel, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }
    }
}
